home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 176-200 / disk_185 / examples / cycvb.c < prev   
C/C++ Source or Header  |  1992-05-06  |  3KB  |  126 lines

  1. /*
  2.  * cycvb.c --- Dan Silva's DPaint color cycling interrupt code
  3.  *
  4.  *    Use this as an example for interrupt driven color cycling
  5.  *    If compiled with Lattice, use -v flag on LC2
  6.  *    For an example of subtask cycling, see Display.c
  7.  */
  8.  
  9. #include <exec/types.h>
  10. #include <exec/interrupts.h>
  11. #include <graphics/view.h>
  12. #include <iff/compiler.h>
  13.  
  14. #define MAXNCYCS 4
  15. #define NO  FALSE
  16. #define YES TRUE
  17. #define LOCAL static
  18.  
  19. typedef struct {
  20.     SHORT count;
  21.     SHORT rate;
  22.     SHORT flags;
  23.     UBYTE low, high;  /* bounds of range */
  24.     } Range;
  25.  
  26. /* Range flags values */
  27. #define RNG_ACTIVE  1
  28. #define RNG_REVERSE 2
  29. #define RNG_NORATE 36  /* if rate == NORATE, don't cycle */
  30.  
  31. /* cycling frame rates */
  32. #define OnePerTick   16384
  33. #define OnePerSec    OnePerTick/60
  34.  
  35. extern Range  cycles[];
  36. extern BOOL   cycling[];
  37. extern WORD   cycols[];
  38. extern struct ViewPort *vport;
  39. extern SHORT  nColors;
  40.  
  41.  
  42. MyVBlank()  {
  43.    int i,j;
  44.    LOCAL  Range *cyc;
  45.    LOCAL  WORD  temp;
  46.    LOCAL  BOOL  anyChange;
  47.  
  48. #ifdef IS_AZTEC
  49. #asm
  50.        movem.l  a2-a7/d2-d7,-(sp)
  51.        move.l   a1,a4
  52. #endasm
  53. #endif
  54.  
  55.    if (cycling)  {
  56.       anyChange = NO;
  57.       for (i=0; i<MAXNCYCS; i++)  {
  58.          cyc = &cycles[i];
  59.          if ( (cyc->low == cyc->high) ||
  60.               ((cyc->flags&RNG_ACTIVE) == 0) ||
  61.               (cyc->rate == RNG_NORATE) )
  62.                  continue;
  63.  
  64.          cyc->count += cyc->rate;
  65.          if (cyc->count >= OnePerTick)  {
  66.             anyChange = YES;
  67.             cyc->count -= OnePerTick;
  68.  
  69.             if (cyc->flags&RNG_REVERSE)  {
  70.                temp = cycols[cyc->low];
  71.                for (j=cyc->low; j < cyc->high; j++)
  72.                   cycols[j] = cycols[j+1];
  73.                cycols[cyc->low] = temp;
  74.                }
  75.             else  {
  76.                temp = cycols[cyc->high];
  77.                for (j=cyc->high; j > cyc->low; j--)
  78.                   cycols[j] = cycols[j-1];
  79.                cycols[cyc->low] = temp;
  80.                }
  81.             }
  82.          }
  83.       if (anyChange) LoadRGB4(vport,cycols,nColors);
  84.       }
  85.  
  86. #ifdef IS_AZTEC
  87.       ;   /* this is necessary */
  88. #asm
  89.       movem.l  (sp)+,a2-a7/d2-d7
  90. #endasm
  91. #endif
  92.  
  93.    return(0);  /* interrupt routines have to do this */
  94.    }
  95.  
  96.  
  97. /*
  98.  *  Code to install/remove cycling interrupt handler
  99.  */
  100.  
  101. LOCAL char myname[] = "MyVB";  /* Name of interrupt handler */
  102. LOCAL struct Interrupt intServ;
  103.  
  104. typedef void (*VoidFunc)();
  105.  
  106. StartVBlank()  {
  107. #ifdef IS_AZTEC
  108.    intServ.is_Data = GETAZTEC();  /* returns contents of register a4 */
  109. #else
  110.    intServ.is_Data = NULL;
  111. #endif
  112.    intServ.is_Code = (VoidFunc)&MyVBlank;
  113.    intServ.is_Node.ln_Succ = NULL;
  114.    intServ.is_Node.ln_Pred = NULL;
  115.    intServ.is_Node.ln_Type = NT_INTERRUPT;
  116.    intServ.is_Node.ln_Pri  = 0;
  117.    intServ.is_Node.ln_Name = myname;
  118.    AddIntServer(5,&intServ);
  119.    }
  120.  
  121. StopVBlank() { RemIntServer(5,&intServ); }
  122.  
  123. /**/
  124.  
  125.  
  126.